package cn.it.ygh.controller;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.it.ygh.pojo.Agent;
import cn.it.ygh.pojo.Apply;
import cn.it.ygh.pojo.Order;
import cn.it.ygh.service.HouseEnsureService;

@Controller
public class HouseEnsureController {
	@Autowired
	private HouseEnsureService houseEnsureService;
	
	@RequestMapping(value = "/getOrderData.do",method = RequestMethod.GET)
	@ResponseBody
	public Map<Object,Object> getOrderData(@RequestParam(value = "pageStart") int pageStart,@RequestParam(value="pageSize") int pageSize,HttpSession session){
	
		System.out.println(pageStart);
		System.out.println(pageSize);
		
		Agent ag = (Agent)session.getAttribute("ag");
		String agentAccount = ag.getAgentAccount();
		
		List<Order> orderList = houseEnsureService.getOrderData((pageStart-1)*pageSize,pageSize,agentAccount);
		int total = houseEnsureService.getOrderTotal(agentAccount);
		Map<Object,Object> info = new HashMap<Object,Object>();
		info.put("data",orderList);
		info.put("total",total);
		return info;

	}
	
	@RequestMapping(value = "/getApplyData.do",method = RequestMethod.GET)
	@ResponseBody
	public Map<Object,Object> getApplyData(@RequestParam(value = "pageStart") int pageStart,@RequestParam(value="pageSize") int pageSize,HttpSession session){
		
		System.out.println(pageStart);
		System.out.println(pageSize);
		
		Agent ag = (Agent)session.getAttribute("ag");
		String agentAccount = ag.getAgentAccount();
		
		List<Apply> applyList = houseEnsureService.getApplyData((pageStart-1)*pageSize,pageSize,agentAccount);
		int total = houseEnsureService.getApplyTotal(agentAccount);
		Map<Object,Object> info = new HashMap<Object,Object>();
		info.put("data",applyList);
		info.put("total",total);
		return info;
	}
	
	
}
